#!/bin/bash
####################################################################
# Prey Geo Module Linux Functions - by Tomas Pollak (bootlog.org)
# URL: http://preyproject.com
# License: GPLv3
####################################################################

get_wifi_access_points() {

	get_wifi_device
	if [ -n "$wifi_device" ]; then

		log " -- Detected wireless device at ${wifi_device}."

		wifi_points=`\`which iwlist\` $wifi_device scan | grep -v "Frequency" | egrep 'Address|Channel|ESSID|Signal' | tr -d '\n' | \
			sed -e 's/  //g' -e 's/Cell[0-9 -]*//g' \
			-e "s/Quality[0-9=:\/ ]*Signal//g" \
			-e 's/\([A-F0-9]\):\([A-F0-9]\)/\1-\2/g' \
			-e 's/Channel:\([0-9]*\)/"channel": \1,/g' \
			-e 's/Address: \?\([A-F0-9-]\{17\}\)/{"mac_address": "\1", /g' \
			-e 's/ESSID:"\([^"]*\)"/"ssid": "\1", /g' \
			-e 's/level.\([0-9\/-]*\) \?dBm\([^"{]*\)/"signal_strength": \1, /g' \
			-e 's/, {/}, {/g' \
			-e "s/\\\x..//g" \
			-e "s/, $/}/"`

	else

		log " -- No wireless device detected."

	fi

}
